<html>
<head>
<title>A Comprehensive Example</title>
</head>
<body>
<table width=100%>
<tr>
<td align=left>
<a href="../stepbystep/index.html"><img src=../../images/PreviousArrow.gif width=26 height=26 align=bottom border=0 alt="Previous | "></a><a
href="../end.html"><img src=../../images/NextArrow.gif width=26 height=26 align=bottom border=0 alt="Next | "></a><a
href="../../index.html"><img src=../../images/WayUpArrow.gif width=26 height=26 align=bottom border=0 alt="Trail Map | "></a><a
href="../index.html"><img src=../../images/nativeHeader.gif width=26 height=26 align=bottom border=0 alt="Integrating Native Methods into Java Programs | "></a>
<td>
<td align=right>
<a href="TOC.html"><strong><em>Table of Contents</em></strong></a>
</td>
</tr>
</table>
<p>
<hr size=4>

<h1>
     A Comprehensive Example
</h1>
<p>
<blockquote>

This lesson in under construction. However, we are making the source code
for the example available for you to look at now. By reading the source and
the comments within the code, you should be able to figure out the example.
In addition, you should be able to figure out how to return values from and
pass values into native methods, and about some of the helper functions and
macros provided by the Java development environment that provide the connection
between the Java language and C.

<h4>The Example</h4>
<blockquote>
The example consists of a simple "character-replace" program. You invoke
the program with these command line arguments:
<blockquote>
<pre>
<em>char1 char2 inputfile outputfile</em>
</pre>
</blockquote>
The <code>Replace</code> program reads from <em>inputfile</em>,
replaces all occurrences of <em>char1</em> with <em>char2</em>,
and writes the results to <em>outputfile</em>.

</blockquote>

<h4>The Source Files</h4>
<blockquote>

<dl>

<dt><a href=example/Replace.java>Replace.java</a>
<dd> Contains the main program.

<dt><a href=example/File.java>File.java</a>
<dd> Contains the <code>File</code> superclass that provides
     provides basic file and path manipulation with the expectation that
     subclasses will provide the actual file management code depending on
     the file semantics they want to present.

<dt><a href=example/InputFile.java>InputFile.java</a>
<dd> Contains the <code>InputFile</code> class (a subclass of <code>File</code>)
     that implements a read-only input file. <br>
     <strong>Note:</strong> This class has several native methods whose
     implementations are written in the C programming language.

<dt><a href=example/OutputFile.java>OutputFile.java</a>
<dd> Contains the <code>OutputFile</code> class (a subclass of <code>File</code>)
     that implements a write-only output file. <br>
     <strong>Note:</strong> This class has several native methods whose
     implementations are written in the C programming language.

<dt><a href=example/file.c>file.c</a>
<dd> Contains the C implementations for the native methods defined by
     both the <code>InputFile</code> and <code>OutputFile</code> classes.

</dl>
</blockquote>

<h4>Files Generated by <code>javah</code></h4>
<blockquote>
<dl>

<dt><a href=example/File.h>File.h</a>
<dt><a href=example/InputFile.h>InputFile.h</a>
<dt><a href=example/OutputFile.h>OutputFile.h</a>
<dd> C header files generated by <code>javah</code>.

<dt><a href=example/File.c>File.c</a>
<dt><a href=example/InputFile.c>InputFile.c</a>
<dt><a href=example/OutputFile.c>OutputFile.c</a>
<dd> C stub files generated by <code>javah -stubs</code>.

</dl>
</blockquote>

<h4>Instructions</h4>
<ol>
<li>
Compile the <code>.java</code> files into <code>.class</code> files using the
Java compiler

<li>
Compile all of the C code into a dynamically loadable library named "file".
If you don't know how to do this, follow the instructions in
<a href=../stepbystep/step6.html>Step 6: Create a Dynamically Loadable Library</a>
<a href=../stepbystep/step6.html><img src=../../images/nativeIcon.gif width=20 height=20 border=0></a>
in the <em>Step By Step</em> lesson.

<li>
Run the program using the Java interpreter.

</ol>

</blockquote>
<p>
<hr size=4>
<p>
<table width=100%>
<tr>
<td align=left>
<a href="../stepbystep/index.html"><img src=../../images/PreviousArrow.gif width=26 height=26 align=top border=0 alt="Previous | "></a><a
href="../end.html"><img src=../../images/NextArrow.gif width=26 height=26 align=top border=0 alt="Next | "></a><a
href="../../index.html"><img src=../../images/WayUpArrow.gif width=26 height=26 align=top border=0 alt="Trail Map | "></a><a
href="../index.html"><img src=../../images/nativeHeader.gif width=26 height=26 align=top border=0 alt="Integrating Native Methods into Java Programs | "></a>
<td>
<td align=right>
<a href="TOC.html"><strong><em>Table of Contents</em></strong></a>
</td>
</tr>
</table>
</body>
</html>
